﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Master/MasterPage.master" AutoEventWireup="true" CodeBehind="WarningSetupForCompany.aspx.cs" Inherits="HZ.Supervise.Web.Message.WarningSetupForCompany" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
<link href="../Style/global.css" rel="stylesheet" type="text/css" />

    <script src="../Scripts/jquery-1.3.2.min.js" type="text/javascript"></script>

    <script src="../Scripts/jquery.validate.js" type="text/javascript"></script>

    <script src="../Scripts/localization/messages_cn.js" type="text/javascript"></script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
 <script type="text/javascript">
        $().ready(function() {
            $("form").validate();
        });
    
    </script>
 <script type="text/javascript" language="javascript">
    //选择企业
     function SelectCompany() {
        var AreaName = document.getElementById("ctl00_ContentPlaceHolder1_txtArea");
        var AreaId = document.getElementById("ctl00_ContentPlaceHolder1_hfdRecivedArea");

        if (AreaName.value == null || AreaName.value == "") {
            alert("请先选择地区");

        }
        else {

            window.open('../Common/SelectCompany.aspx?flag=1&AreaId=' + AreaId.value + '&AreaName=' + AreaName.value + '', 'selectReciever', 'width=800,height=700,resizable=0,scrollbars=1, status=0, toolbar=0, menubar=0');
        }
    }
    function SelectGoods() {
        var Sort = document.getElementById("ctl00_ContentPlaceHolder1_ddlDrugSort");
        window.open('../Common/SelectGoods.aspx?SortId=' + Sort.value + '', 'selectReciever', 'width=800,height=700,resizable=0,scrollbars=1, status=0, toolbar=0, menubar=0');

    }

    //将选择的药品放入文本框
    function insertGoodsInfo(GoodsId, ProductName) {


        var varGoodsId = GoodsId;
        var varProductName = ProductName;

        var GoodsID = document.getElementById("ctl00_ContentPlaceHolder1_hdfRecivedGoods");
        var ProductName = document.getElementById("ctl00_ContentPlaceHolder1_txtDrug");

        ProductName.value = varProductName;
        GoodsID.value = varGoodsId;

    }

    //将选择的企业放入文本框
    function insertCompanyInfo(HospitalId, HospitalName) {
        var varHospitalId = HospitalId;
        var varHospitalName = HospitalName;

        var hospitalID = document.getElementById("ctl00_ContentPlaceHolder1_hdfRecivedCompany");
        var hospitalName = document.getElementById("ctl00_ContentPlaceHolder1_txtCompany");
        hospitalName.value = varHospitalName;
        hospitalID.value = varHospitalId;



    }

    //将选择的地区放入文本框
    function insertAreaInfo(AreaId, AreaName) {


        var varAreaId = AreaId;
        var varAreaName = AreaName;

        var RecievedareaID = document.getElementById("ctl00_ContentPlaceHolder1_hfdRecivedArea");
        var RecievedareaName = document.getElementById("ctl00_ContentPlaceHolder1_txtArea");

        RecievedareaName.value = varAreaName;
        RecievedareaID.value = varAreaId;

        //显示选择企业的CheckBox
        var Show = document.getElementById("showCompanys");
        Show.style.display = 'block';

    }
    function ShowCompany() {
        var chk = document.getElementById("chk");
        if (chk.checked == true) {
            document.getElementById("company").style.display = "block";
            document.getElementById("txtCompanys").style.display = "block";
            document.getElementById("selectCompany").style.display = "block";
            document.getElementById("sort").style.display = "block";
            document.getElementById("ddlSort").style.display = "block";
        }
        else {

            document.getElementById("company").style.display = "none";
            document.getElementById("txtCompanys").style.display = "none";
            document.getElementById("selectCompany").style.display = "none";
            document.getElementById("sort").style.display = "none";
            document.getElementById("ddlSort").style.display = "none";
            var companyID = document.getElementById("ctl00_ContentPlaceHolder1_hdfRecivedCompany");
            var companyName = document.getElementById("ctl00_ContentPlaceHolder1_txtCompany");
            companyName.value = "";
            companyID.value = "";
        }
    }
    function SelectChange() {
        //下拉框选择药品类别时控制界面的显示
        var ddl = document.getElementById("ctl00_ContentPlaceHolder1_ddlDrugSort");
        if (ddl.value == '---请选择---') {
            //药品名
            document.getElementById('ProductName').style.display = "none";
            //药品名文本框
            document.getElementById("txtProductName").style.display = "none";
            //选择药品按钮
            document.getElementById("selectProductName").style.display = "none";
            //预警金额与预警数量
            document.getElementById("warning").style.display = "none";
            //预警级别 预警范围
            document.getElementById("LevelRange").style.display = "none";
            document.getElementById("ConnectType").style.display = "none";
            document.getElementById("ddlConnectTypes").style.display = "none"; 
        }
        else {
            document.getElementById('ProductName').style.display = "block";
            document.getElementById("txtProductName").style.display = "block";
            document.getElementById("selectProductName").style.display = "block";
            document.getElementById("warning").style.display = "block";
            document.getElementById("LevelRange").style.display = "block";
            document.getElementById("ConnectType").style.display = "block";
            document.getElementById("ddlConnectTypes").style.display = "block"; 
        }
    }

    //验证预警规则的预警范围 预警数量 预警金额
    function ValidateWarning() {
        var flag = true;
        //ddlTime预警范围
        var ddlTime = document.getElementById('ctl00_ContentPlaceHolder1_ddlTime');
        var txtTime = document.getElementById('ctl00_ContentPlaceHolder1_txtTimeOfRange');
        //ddlCountCompare、ddlCountCompare2预警数量范围比较方式
        var ddlCountCompare = document.getElementById('ctl00_ContentPlaceHolder1_ddlCountCompare');
        var ddlCountCompare2 = document.getElementById('ctl00_ContentPlaceHolder1_ddlCountCompare2');
        var txtCount = document.getElementById('ctl00_ContentPlaceHolder1_txtCount');
        var txtCount2 = document.getElementById('ctl00_ContentPlaceHolder1_txtCount2');


        //下拉框ddlAmountCompare、ddlAmountCompare2预警金额范围比较方式（value值： 1大于等于 0小于等于）
        var ddlAmountCompare = document.getElementById('ctl00_ContentPlaceHolder1_ddlAmountCompare');
        var ddlAmountCompare2 = document.getElementById('ctl00_ContentPlaceHolder1_ddlAmountCompare2');
        var txtAmount = document.getElementById('ctl00_ContentPlaceHolder1_txtAmount');
        var txtAmount2 = document.getElementById('ctl00_ContentPlaceHolder1_txtAmount2');
        //下拉框ddlTime的value 1是周 2月  3季度 4年
        if (ddlTime.value == '1') {
            if (txtTime.value > 5) {
                alert("监控周不可以超过5个自然周");
                flag = false;
            }
        }
        if (ddlTime.value == '2') {
            if (txtTime.value > 5) {
                alert("监控周不可以超过5个自然月");
                flag = false;
            }
        }
        if (ddlTime.value == '3') {
            if (txtTime.value > 5) {
                alert("监控周不可以超过5个自然季度");
                flag = false;
            }
        }
        //对预警数量判断
        if (ddlCountCompare.value == "1") {
            //数量大于第一个数字，且大于第二个数字
            if (ddlCountCompare2.value == "1") {
                alert('预警数量不可以同时大于等于');
                flag = false;
            }
        }
        else {
            //数量小于第一个数字，且小于第二个数字
            if (ddlCountCompare2.value == "0") {
                alert('预警数量不可以同时小于等于');
                flag = false;
            }
        }
        //对预警金额判断
        if (ddlAmountCompare.value == "1") {
            //数量大于第一个数字，且大于第二个数字
            if (ddlAmountCompare2.value == "1") {
                alert('预警金额不可以同时大于等于');
                flag = false;
            }
        }
        else {
            //数量小于第一个数字，且小于第二个数字
            if (ddlAmountCompare2.value == "0") {
                alert('预警数量不可以同时小于等于');
                flag = false;
            }
        }
        return flag;
    }
    </script>
<div id="tabnav">
        <ul>
            <li class="active"><a href="WarningSetupForHospital.aspx">药品预警设置</a></li>    
             <li><a href="WarningSetupTimeForHospital.aspx">响应时间预警设置</a></li>
            <li><a href="WarningStart.aspx">已启动的预警</a></li>
            <li><a href="WarningStop.aspx">禁用的预警</a></li>
        </ul>
         <ul>
            <li >
                <a href="WarningSetupForHospital.aspx" >医院药品规则制定</a>
            </li>
            <li class="active">
                <a href="WarningSetupForCompany.aspx" >企业药品规则制定</a>
            </li>            
        </ul>
    </div>
 <div id="tabcontent">
    
         <table class="querylist">
                  <tr>
                      <th align="right">
                          地区
                      </th>
                      <td align="left">
                         <asp:TextBox ID="txtArea" runat="server" CssClass="required" Width="250px"></asp:TextBox>
                         <asp:HiddenField ID="hfdRecivedArea" runat="server" EnableViewState="true" />
                         <asp:HiddenField ID="hfdRecivedAreaName" runat="server" EnableViewState="true" />
                         <input type="button" value="选择地区" class="btn" onclick="window.open('../Common/SelectArea.aspx','selectReciever','width=400,height=500,resizable=0,scrollbars=1, status=0, toolbar=0, menubar=0');"/> 
                      </td>
                      <td align="left" id="showCompanys" style="display:none">
                        <b>选择企业</b>
                        <input type="checkbox" id="chk" onclick="javascript:ShowCompany();" />
                      </td>
                     <th id="company" style="display:none" align="right">
                          企业
                      </th>
                      <td id="txtCompanys" style="display:none" align="left">
                          <asp:TextBox ID="txtCompany" runat="server" CssClass="required" Width="250px"></asp:TextBox>
                          <asp:HiddenField ID="hdfRecivedCompany" runat="server" EnableViewState="true" />                            
                      </td>
                      <td id="selectCompany" style="display:none" align="left">
                          <%--<asp:Button ID="btnSelectCompany" runat="server" CssClass="btn"  Text="选择企业"/>--%>
                           <%--<input type="btnSelectCom" value="选择企业" class="btn"onclick="window.open('../Common/SelectHospital.aspx','selectReciever','width=300,height=450,resizable=0,scrollbars=0, status=0, toolbar=0, menubar=0');"/>--%>
                            <input type="button" value="选择企业" class="btn" onclick="javascript:SelectCompany();"/>
                      </td>
                  </tr>                 
                  <tr>
                      <th id="sort" style="display:none" align="right">
                          药品类别</th>
                      <td id="ddlSort" style="display:none" align="left">
                          <asp:DropDownList ID="ddlDrugSort"  runat="server">
                          
                         </asp:DropDownList>                    
                      </td>    
                      <td>
                      </td>                 
                          <th style="display:none" id="ProductName" align="right">
                          药品名称
                          </th>
                      <td style="display:none" id="txtProductName" align="left">
                          <asp:TextBox ID="txtDrug" runat="server"  Width="250px" ></asp:TextBox>
                           <asp:HiddenField ID="hdfRecivedGoods" runat="server" EnableViewState="true" />
                      </td>
                      <td style="display:none" id="selectProductName" align="left">
                        <input type="button" value="选择药品" class="btn"  onclick="javascript:SelectGoods();"/>                             
                      </td>
                  </tr>
                 
                  <tr id="warning" style="display:none">
                      <th align="right">
                          预警数量</th>
                      <td align="left" colspan="2">
                           <asp:DropDownList ID="ddlCountCompare" runat="server">
                              <asp:ListItem Value="1" Selected="True">大于等于</asp:ListItem>
                              <asp:ListItem Value="0">小于等于</asp:ListItem>
                          </asp:DropDownList>
                          <asp:TextBox ID="txtCount" runat="server" Width="100px" CssClass="digits" MaxLength="20"></asp:TextBox>
                          <asp:DropDownList ID="ddlCountCompare2" runat="server">
                              <asp:ListItem Value="1" Selected="True">大于等于</asp:ListItem>
                              <asp:ListItem Value="0">小于等于</asp:ListItem>
                          </asp:DropDownList>  
                          <asp:TextBox ID="txtCount2" runat="server" Width="100px" CssClass="digits" MaxLength="20"></asp:TextBox>
                      </td>
                      <th align="right">
                              预警金额</th>
                      <td align="left">
                          <asp:DropDownList ID="ddlAmountCompare" runat="server">
                              <asp:ListItem Value="1"  Selected="True">大于等于</asp:ListItem>
                              <asp:ListItem Value="0">小于等于</asp:ListItem>
                          </asp:DropDownList>
                          <asp:TextBox ID="txtAmount" runat="server" Width="100px" CssClass="digits " MaxLength="50"></asp:TextBox>
                          <asp:DropDownList ID="ddlAmountCompare2" runat="server">
                              <asp:ListItem Value="1" Selected="True">大于等于</asp:ListItem>
                              <asp:ListItem Value="0">小于等于</asp:ListItem>
                          </asp:DropDownList>
                          <asp:TextBox ID="txtAmount2" runat="server" Width="100px" CssClass="digits " MaxLength="50"></asp:TextBox>
                    </td>
                  </tr>
                   <tr id="LevelRange" style="display:none" >
                   <th align="right">
                          预警级别
                    </th>
                    <td align="left" colspan="2">
                         <asp:DropDownList ID="ddlLevel"  runat="server">
                            <asp:ListItem Text="一级预警" Value="1"></asp:ListItem>
                             <asp:ListItem Text="二级预警" Value="2"></asp:ListItem>
                             <asp:ListItem Text="三级预警" Value="3"></asp:ListItem>
                         </asp:DropDownList>
                    </td>
                   <th align="right">
                          预警范围
                    </th>
                      <td align="left"> 
                        <asp:TextBox ID="txtTimeOfRange" runat="server" Width="200px" CssClass="digits required"  MaxLength="10" ></asp:TextBox>
                      <%--<input type="button" runat="server" id="txtTimeOfRangew" />--%>
                       <asp:DropDownList ID="ddlTime" runat="server" >
                                <asp:ListItem Text="周" Value="1"></asp:ListItem>
                                <asp:ListItem Text="月" Value="2"></asp:ListItem>
                                <asp:ListItem Text="季度" Value="3"></asp:ListItem>
                                <asp:ListItem Text="年" Value="4"></asp:ListItem>
                       </asp:DropDownList>
                      </td>
                     
                  </tr>
                  <tr>
                     <th style="display:none" id="ConnectType" align="right">
                          触发规则：
                    </th>
                      <td style="display:none" id="ddlConnectTypes" align="left"> 
                          <asp:DropDownList ID="ddlConnectType"  runat="server">
                            <asp:ListItem Text="两者都满足" Value="1"></asp:ListItem>
                            <asp:ListItem Text="任意一个满足" Value="0"></asp:ListItem>
                         </asp:DropDownList>
                      </td>
                    <td colspan="3" align="right">
                        <asp:Button ID="btnConfirmMessage" OnClientClick="return ValidateWarning();" runat="server"  Text="制定完毕" CssClass="btn" 
                              onclick="btnConfirmMessage_Click"/>
                    </td>
                  </tr>
              </table>
      
    </div>
<asp:GridView runat="server" ID="gvwWarningStart" CssClass="mainlist"  AutoGenerateColumns="False"
        EmptyDataText="暂无制定的规则！" onrowdatabound="gvwWarningStart_RowDataBound" 
        onrowcancelingedit="gvwWarningStart_RowCancelingEdit" 
        onrowediting="gvwWarningStart_RowEditing" 
        onrowupdating="gvwWarningStart_RowUpdating" DataKeyNames="MessageDetailId">
        <Columns>
               <asp:TemplateField HeaderText="序号">
                <ItemTemplate>
                    <%# Container.DataItemIndex + 1 + AspNetPager1.PageSize * (AspNetPager1.CurrentPageIndex - 1)%></ItemTemplate>
                <HeaderStyle Width="30px" />
            </asp:TemplateField>            
            <asp:TemplateField HeaderText="预警对象" >
              <ItemTemplate>
               <asp:Label ID="lblHospitalName" ToolTip='<%#Eval("CompanyName") %>' runat="server" Text='<%#Eval("CompanyName") %>' ReadOnly="true"></asp:Label>
              </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="地区" >
                   <ItemTemplate>
                       <asp:Label ID="lblAreaName" ToolTip='<%#Eval("AreaName") %>' runat="server" Text='<%#Eval("AreaName") %>' ReadOnly="true"></asp:Label>
                   </ItemTemplate>
            </asp:TemplateField>
            <asp:BoundField DataField="TypeName" HeaderText="类型" ReadOnly="true" />           
            <asp:TemplateField HeaderText="药品名">
                 <ItemTemplate>
                       <asp:Label ID="lblProductName" ToolTip='<%#Eval("ProductName") %>' runat="server" Text='<%#Eval("ProductName") %>' ReadOnly="true"></asp:Label>
                   </ItemTemplate> 
            </asp:TemplateField>
            <asp:BoundField DataField="SortName" HeaderText="类别" ReadOnly="true" />
            <asp:BoundField DataField="AddTime" HeaderText="添加时间" DataFormatString="{0:d}" ReadOnly="true"/>
             <asp:TemplateField HeaderText="比较方式">
                 <ItemTemplate>
                       <asp:Label ID="lblCompare" ToolTip='<%#Eval("CountParentLeft") %>' runat="server" Text='<%#Eval("CountParentLeft") %>' ReadOnly="true"></asp:Label>
                   </ItemTemplate> 
            </asp:TemplateField>
             <asp:TemplateField HeaderText="数量">
                 <ItemTemplate>
                    <asp:TextBox ID="txtCountLeft" runat="server" Text='<%# Bind("CountLeft") %>' ReadOnly="true" Width="90%"></asp:TextBox>
                </ItemTemplate>
                 <EditItemTemplate>
                    <asp:TextBox ID="EditTxtCountLeft" runat="server" Text='<%# Bind("CountLeft") %>' Width="90%"   CssClass="digits required" ></asp:TextBox>
                </EditItemTemplate>        
                 <HeaderStyle Width="100px" />          
            </asp:TemplateField>
            <asp:TemplateField HeaderText="比较方式">
                 <ItemTemplate>
                       <asp:Label ID="lblCompare2" ToolTip='<%#Eval("CountParentRight") %>' runat="server" Text='<%#Eval("CountParentRight") %>' ReadOnly="true"></asp:Label>
                   </ItemTemplate> 
            </asp:TemplateField>
            <asp:TemplateField HeaderText="数量">
                 <ItemTemplate>
                    <asp:TextBox ID="txtCountRight" runat="server" Text='<%# Bind("CountRight") %>' ReadOnly="true" Width="90%"></asp:TextBox>
                </ItemTemplate>
                 <EditItemTemplate>
                    <asp:TextBox ID="EditTxtCountRight" runat="server" Text='<%# Bind("CountRight") %>' Width="90%"   CssClass="digits required" ></asp:TextBox>
                </EditItemTemplate>        
                 <HeaderStyle Width="100px" />          
            </asp:TemplateField>
            <asp:TemplateField HeaderText="比较方式">
                 <ItemTemplate>
                       <asp:Label ID="lblAmountCompare" ToolTip='<%#Eval("AmountParentLeft") %>' runat="server" Text='<%#Eval("AmountParentLeft") %>' ReadOnly="true"></asp:Label>
                   </ItemTemplate> 
            </asp:TemplateField>
            <asp:TemplateField HeaderText="金额">
                 <ItemTemplate>
                    <asp:TextBox ID="txtAmountLeft" runat="server" Text='<%# Bind("AmountLeft") %>' ReadOnly="true" Width="90%"></asp:TextBox>
                </ItemTemplate>
                 <EditItemTemplate>
                    <asp:TextBox ID="EditTxtAmountLeft" runat="server" Text='<%# Bind("AmountLeft") %>' Width="90%" CssClass="number required"></asp:TextBox>
                </EditItemTemplate>  
                 <HeaderStyle Width="100px" />                
            </asp:TemplateField>
            <asp:TemplateField HeaderText="比较方式">
                 <ItemTemplate>
                       <asp:Label ID="lblAmountCompare2" ToolTip='<%#Eval("AmountParentRight") %>' runat="server" Text='<%#Eval("AmountParentRight") %>' ReadOnly="true"></asp:Label>
                   </ItemTemplate> 
            </asp:TemplateField>
            <asp:TemplateField HeaderText="金额">
                 <ItemTemplate>
                    <asp:TextBox ID="txtAmountRight" runat="server" Text='<%# Bind("AmountRight") %>' ReadOnly="true" Width="90%"></asp:TextBox>
                </ItemTemplate>
                 <EditItemTemplate>
                    <asp:TextBox ID="EditTxtAmountRight" runat="server" Text='<%# Bind("AmountRight") %>' Width="90%" CssClass="number required"></asp:TextBox>
                </EditItemTemplate>  
                 <HeaderStyle Width="100px" />                
            </asp:TemplateField>
              <asp:TemplateField HeaderText="预警范围">
                 <ItemTemplate>
                    <asp:TextBox ID="txtDays" runat="server" Text='<%# Bind("Days") %>' ReadOnly="true" Width="70%"></asp:TextBox>
                    <asp:Label ID="lblDayType" runat="server" Text='<%#Eval("DayType") %>'></asp:Label>
                </ItemTemplate>
                 <EditItemTemplate>
                    <asp:TextBox ID="EditTxtDays" runat="server" Text='<%# Bind("Days") %>' Width="70%" CssClass="digits required" ></asp:TextBox>
                    <asp:Label ID="lblDayType" runat="server" Text='<%#Eval("DayType") %>'></asp:Label>
                </EditItemTemplate>   
                <HeaderStyle Width="100px" />            
            </asp:TemplateField>
            <asp:BoundField DataField="Level" HeaderText="预警级别"  ControlStyle-Width="80px"  ReadOnly="true"/>
            <asp:TemplateField HeaderText="修改信息">
                <EditItemTemplate>
                    <asp:LinkButton  ID="lbnUpdate" runat="server" CausesValidation="True" CommandName="Update"
                        OperateType="编辑">更新</asp:LinkButton>              
                       <asp:LinkButton ID="lbnCancel" runat="server" CausesValidation="False" CommandName="Cancel">取消</asp:LinkButton>              
                </EditItemTemplate>
                <ItemTemplate>
                <asp:LinkButton ID="lbnEdit" runat="server" CausesValidation="True" CommandName="Edit" OperateType="编辑">编辑</asp:LinkButton>                   
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField>
                <HeaderTemplate>
                    <input id="addTable_chkAll" name="chkAll" class="chkAll" type="checkbox" onclick="$('input[type=checkbox]').attr('checked', this.checked);" />
                </HeaderTemplate>
                <ItemTemplate>
                    <input type="checkbox" name="chk" class="item" id="chk" value='<%#Eval("MessageDetailId")%>' />
                </ItemTemplate>
                <HeaderStyle Width="25px" />
            </asp:TemplateField>
        </Columns>
    </asp:GridView>
    <div class="page">
        <webdiyer:AspNetPager ID="AspNetPager1" runat="server" 
             onpagechanged="AspNetPager1_PageChanged">
        </webdiyer:AspNetPager>
    </div>
    <div class="listctrl">
        <asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button" UseSubmitBehavior="false" />
        <asp:Button ID="btnDelte" CssClass="btn"
            OnClientClick="if(getcheckcount('请至少选择一个要删除的预警')){ return confirm('确定要删除所选的预警吗？');} return false;" 
            runat="server" Text="删除" onclick="btnDelte_Click" UseSubmitBehavior="true"/>
        <asp:Button ID="btnStart" CssClass="btn"
            OnClientClick="if(getcheckcount('请至少选择一个要启用的预警')){ return confirm('确定要启用所选的预警吗？');} return false;" 
            runat="server" Text="启用" onclick="btnStart_Click" UseSubmitBehavior="true" />
    </div>
</asp:Content>
